interface IResponseData {
  isStream?: boolean;
  sessionId: string;
  getAgentStream?: () => Promise<any>;
  getAgentInvoke?: () => Promise<any>;
}

export async function* useResponseDataGen(params: IResponseData) {
  //  非流式
  if (!params.isStream) {
    const response = await params.getAgentInvoke?.();
    yield response.messages.at(-1).content;
    return;
  }
  const agentStream = await params.getAgentStream?.();
  for await (const chunk of agentStream) {
    const [messageChunk] = chunk;
    yield messageChunk;
  }
}
